package 算法.leetcode.offer.lkh;

import 算法.leetcode.offer.base.TreeNode;

import java.util.Arrays;
import java.util.List;

/**
 * https://leetcode-cn.com/problems/convert-bst-to-greater-tree/
 * @author lchenglong
 * @date 2022/4/20
 */
public class LKH538 {

    public static void main(String[] args) {
        List<Integer> array = Arrays.asList(4,1,6,0,2,5,7,null,null,null,3,null,null,null,8);
        TreeNode root = TreeNode.init(array);
        LKH538 instance = new LKH538();
        TreeNode ans = instance.convertBST(root);
        TreeNode.print(ans);
    }
    int sum = 0;
    public TreeNode convertBST(TreeNode root) {
        if (root != null) {
            convertBST(root.right);
            sum += root.val;
            root.val = sum;
            convertBST(root.left);
        }
        return root;
    }


}
